﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BillFrm.aspx.cs" Inherits="WebApp.BillFrm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>账单查询</title>
    <link rel="stylesheet" type="text/css" href="css/newStyle.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/icon.css" />

    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>

    <script type="text/javascript">
        var PageSize = 20;
        //页面加载
        $(document).ready(function() {
            initData();
            initGrid();
        });

        $(window).resize(function() {
            $('#tb').datagrid('resize');
        });

        function doSearch() {
            var validate = $('#fm').form('validate');
            if (!validate)
                return;
            var params = getParams(false);
            var url = "ExportWTS.ashx";

            $.post(url, params, function(data) {
                if (data)
                    $('#tb').datagrid('loadData', data);
            }, "json");
        }

        function getParams(expt) {
            return $.extend({}, {
                DataType: 'Bill',
                FeeType: $('#qFeeType').combobox('getValue'),
                SDate: $('#qSDate').datebox('getValue'),
                EDate: $('#qEDate').datebox('getValue'),
                Target: $('#qTarget').combobox('getValue'),
                Export: expt
            });
        }

        function initData() {
            $('#qSDate').datebox('setValue', DateFormatter(new Date().DateAdd('m', -1)));
            $('#qEDate').datebox('setValue', DateFormatter(new Date()));

            $.getJSON("JSONHandler.ashx?DataType=FeeType", function(result) {
                $('#qFeeType').combobox('loadData', result);
                $('#qFeeType').combobox('setValue', 1);
                bindTarget(1);
            });
        }

        //加载表格datagrid
        function initGrid() {
            //加载数据
            $('#tb').datagrid({
                toolbar: '#searchBar',
                width: 'auto',
                //fit:true,
                //fitColumns: true,
                height: '500',
                striped: true,
                singleSelect: true,
                //url: 'JSONHandler.ashx',
                //queryParams: params,
                loadMsg: '数据加载中请稍后……',
                pagination: false,
                rownumbers: true,
                columns: [[
        { field: '订舱号', title: '订舱号' },
        { field: '箱型', title: '箱型', formatter: brFormat },
        { field: '箱号', title: '箱号', formatter: brFormat },
        { field: '封号', title: '封号', formatter: brFormat },
        { field: '装货地点', title: '装货地点' },
        { field: '装货日期', title: '装货日期' },
        { field: '费用', title: '费用', formatter: brFormat },
        { field: '总额', title: '总额' },
        { field: '备注', title: '备注' }
    ]]
            });

        }

        function brFormat(val, rec) {
            if (val) {
                var re = new RegExp("\n", "g");
                return val.replace(re, "<br />");
            }
            return val;
        }

        function setTargetField(o) {
            return o;
        }

        function bindTarget(feeType) {
            var params = 'DataType=FeeTarget';
            var v = 'id';
            var t = 'name';

            if (feeType == 1) {
                params = 'DataType=Client&AddKey=false';
                t = 'fullName';
            }
            var u = 'JSONHandler.ashx?' + params;
            $(function() {
                $('#qTarget').combobox({
                    valueField: setTargetField(v),
                    textField: setTargetField(t)
                });
            });

            $.getJSON(u, function(result) {
                $('#qTarget').combobox('loadData', result);
            });
        }

        function resetAll() {
            $('#fm').form('clear');
        }

        function openWin(url, title, width, height) {
            $('#winFrame').prop('src', url);
            $('#winFrame').prop('style').height = height + 'px';
            $('#winFrame').prop('style').width = width + 'px';
            $('#win').window({
                title: title,
                width: width + 'px',
                height: height + 'px',
                modal: true
            });
        }

        function feeTypeChange(rec) {
            bindTarget(rec.Value);
        }

        function exportBill() {
            var params = jQuery.param(getParams(true));
            window.open("ExportWTS.ashx?" + params);
        }
    </script>

</head>
<body style="padding: 5px">
    <form id="form1" runat="server">
    </form>
    <form id="fm">
    <div id="searchBar" style="padding: 5px; height: auto">
        <span>账单类型：</span>
        <input class="easyui-combobox" id="qFeeType" data-options="valueField:'Value',textField:'Name',onSelect:feeTypeChange"
            style="width: 100px;" required="true">
        <span>账单时段：</span>
        <input id="qSDate" class="easyui-datebox" data-options="formatter:DateFormatter,parser:DateParser"
            style="width: 90px" required="true" />至
        <input id="qEDate" class="easyui-datebox" data-options="formatter:DateFormatter,parser:DateParser"
            style="width: 90px" required="true" />
        <span>结算对象：</span><input class="easyui-combobox" id="qTarget" data-options="valueField:'id',textField:'name'"
            style="width: 200px;" required="true">
        <a href="#" class="easyui-linkbutton" iconcls="icon-search" plain="true" onclick="doSearch();">
            搜索</a> <a href="#" class="easyui-linkbutton" iconcls="icon-undo" plain="true" onclick="resetAll();">
                重置</a> <a href="#" class="easyui-linkbutton" iconcls="icon-print" plain="true" onclick="exportBill();">
                    导出账单</a>
    </div>
    <table id="tb" class="easyui-datagrid" title="账单">
    </table>
    <div id="win">
        <iframe id="winFrame" src="" style="width: 0px; height: 0px" frameborder="0" scrolling="no">
        </iframe>
    </div>
    </form>
</body>
</html>
